<?php

namespace Biz\model\salesRebate;

use Doraemon\pockets\datebase\BaseDbModel;
use Biz\model\trade\Order as mOrder;

class SalesOrder extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_sales_rebate';

    const _DATABASE_ = 'biz_sales_rebate';

    const _TABLE_NAME = 'sales_order';

    const TYPE_PERSONAL = 1;//个人账户
    const TYPE_COMPANY = 2;//公司账户

    const STATUS_NORMAL = 0;
    const STATUS_ACCOUNTED = 1;//已入账
    const STATUS_INVALID = 3;//已失效
    const STATUS_DELETE = 9;


    public static function getAllByWhere($files = '*', $where = [])
    {
        $data = self::select($files, $where);
        return $data;
    }

    public static function getOneByWhere($files = '*', $where = [])
    {
        $data = self::get($files, $where);
        return $data;
    }

    public static function getMasterSalesOrder($uid, $orderNo, $goodsId, $skuId)
    {
        return self::get_master('*', ['uid' => $uid, 'order_no' => $orderNo, 'goods_id' => $goodsId, 'sku_id' => $skuId, 'status[!]' => self::STATUS_DELETE]);
    }

    public static function addData($data)
    {
        $ret = self::insert($data);
        if ($ret->errorCode() !== '00000') {
            throw new \Exception('数据库操作错误');
        }
        return true;
    }

    public static function updateData($data, $where)
    {
        $ret = self::update($data, $where);
        if ($ret->errorCode() !== '00000') {
            throw new \Exception('数据库操作错误');
        }
        return true;
    }

}